import 'package:appflutterhomeschool/api/api_service.dart';
import 'package:appflutterhomeschool/api/dio_utils.dart';
import 'package:appflutterhomeschool/common/common.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

///用户： ninetailedfox
///时间： 2020/6/27
///邮箱： 1037438704@qq.com
///功能： 修改密码状态管理
class ChangePasswordViewModel extends ChangeNotifier {
  BuildContext me;
  String passwordText;

  //是否显示密码
  bool obscure1Text = true;
  bool obscure2Text = true;

  ChangePasswordViewModel(this.me);
  TextEditingController oldPassword = TextEditingController();
  TextEditingController newPassword = TextEditingController();


  initView() {}

  initEvent(int tag) {
    switch (tag) {
      case 0:
        obscure1Text = !obscure1Text;
        notifyListeners();
        break;
      case 1:
        obscure2Text = !obscure2Text;
        notifyListeners();
        break;
      case 2:
//    修改密码
        DioUtils.getInstance().post(ApiService.updatePasswordByOld, {
          "old_password" :oldPassword.text,
          "new_password" :newPassword.text,
          "token" :Constant.getToken(),
        }, (successCallBack){
          Fluttertoast.showToast(msg: successCallBack["message"]);
          Navigator.pop(me);
        }, (errorCallBack){

        });
        break;
      case 3:
        break;
      default:
        break;
    }
  }
}
